﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Search : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            bindData();
        }
    }

    public void bindData()
    {
        string Key = Request.QueryString["Key"];
        string LinhVuc = Request.QueryString["LinhVuc"];
        string Quan = Request.QueryString["Quan"];
        if (!Key.Equals(""))
            divKey.InnerHtml ="<div style='float:left;width:150px'>Từ khóa: </div>" +Key;
        if (!LinhVuc.Equals("tất cả"))
            divLinhVuc.InnerHtml ="<div style='float:left;width:150px'>Lĩnh vực: </div>"+LinhVuc;
        if (!Quan.Equals("tất cả"))
            divQuan.InnerHtml = "<div style='float:left;width:150px'>Quận: </div>"+Quan;
        string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
        SqlConnection conn = new SqlConnection(connStr);
        SqlCommand com = new SqlCommand();
        com.Connection = conn;
        com.CommandText = "search";
        com.Parameters.AddWithValue("@Key",Key);
        com.Parameters.AddWithValue("@LinhVuc", LinhVuc);
        com.Parameters.AddWithValue("@Quan", Quan);
        com.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = com;
        DataSet ds = new DataSet();
        da.Fill(ds);
        CollectionPager1.BindToControl = DataList1;
        CollectionPager1.DataSource = ds.Tables[0].DefaultView;
        DataList1.DataSource = CollectionPager1.DataSourcePaged;
        DataList1.DataBind();
        KetQua.InnerHtml = "<div style='float:left;width:180px'>Số kết quả tìm thấy: </div>" + ds.Tables[0].Rows.Count.ToString();
    }
    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName.Equals("MaDV"))
        {
            string MaDV = e.CommandArgument.ToString();
            Session["MaDV"] = MaDV;
            Response.Redirect("ChiTietDichVu.aspx#jump");
        }
    }
}